package com.agd.quick.states;
//h
import org.andengine.entity.scene.ITouchArea;
import org.andengine.input.touch.TouchEvent;

import android.view.KeyEvent;

import lib.elementgame.GameSprite;
import lib.engine.GameEngine;
import lib.engine.GameState;

public class HelpState extends GameState {
	
	private GameSprite HELP_BG;
	private static GameSprite backgroundFloor;
	
	private float x1;
    private float x2;
    private boolean keluar;
    
	public HelpState(GameEngine engine) {
		super(engine);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
			ITouchArea pTouchArea, float pTouchAreaLocalX,
			float pTouchAreaLocalY) {
		// TODO Auto-generated method stub
		if(pSceneTouchEvent.isActionDown()){
			x1 = pTouchAreaLocalX;
		}
        if (pSceneTouchEvent.isActionMove()) {
                x2 = pTouchAreaLocalX;
                if(engine.camera.getCenterX() - (x2-x1) < 400){
                	engine.camera.setCenter(400, engine.camera.getCenterY());
                }
                else if(engine.camera.getCenterX() - (x2-x1) > 600){
                	engine.camera.setCenter(600, engine.camera.getCenterY());
                }
                else{
                	engine.camera.setCenter(engine.camera.getCenterX() - (x2-x1), engine.camera.getCenterY());
                }
        }
		return false;
	}

	@Override
	public void initComponent() {
		// TODO Auto-generated method stub
		backgroundFloor = new GameSprite(LDR_SPRITE_BACKGROUND, engine);
		HELP_BG		= new GameSprite(HELP_SPRITE_BG, engine);
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		keluar = false;
		HELP_BG.setWidth(1020);
		HELP_BG.setHeight(480);
		backgroundFloor.setWidth(1200);
        backgroundFloor.setHeight(480);
		
	}

	@Override
	protected void attach() {
		// TODO Auto-generated method stub
		engine.scene.attachChild(backgroundFloor);
		engine.scene.attachChild(HELP_BG);
	
	}

	@Override
	protected void detach() {
		// TODO Auto-generated method stub
		backgroundFloor.detachSelf();
		HELP_BG.detachSelf();

	}

	@Override
	protected void setPosition() {
		// TODO Auto-generated method stub
		HELP_BG.setPosition(0,0);

	}

	@Override
	protected void registerTouch() {
		// TODO Auto-generated method stub
		engine.scene.registerTouchArea(backgroundFloor);
	}

	@Override
	protected void unregisterTouch() {
		// TODO Auto-generated method stub	
		engine.unregisterSceneTouch(backgroundFloor);
	}

	@Override
	protected void onUpdate() {
		// TODO Auto-generated method stub
		if(keluar){
			exitState(MainMenuState);
		}
	}

	@Override
	protected void onPaused() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onResumed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onKeyUp(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			keluar = true;
		}
	}

	@Override
	public void initLoading() {
		// TODO Auto-generated method stub
		
	}

}
